package com.cy.pj.sys.controller;

import com.cy.pj.sys.entity.SysUser;
import com.cy.pj.sys.entity.SysUserMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/")
@Controller
public class PageController {
    @Autowired
    private SysMenuService sysMenuService;

    //主页
    @RequestMapping("doIndexUI")
    public String doIndexUI(Model model){
        /*SysUser user= ShiroUtils.getUser();
        model.addAttribute("user",user);*/
        SysUser user=(SysUser)
                SecurityUtils.getSubject().getPrincipal();//从session获取登录用户
        model.addAttribute("username",user.getUsername());

        List<SysUserMenu> userMenus=sysMenuService.findUserMenusByUserId(user.getId());
        for(SysUserMenu userMenu:userMenus){
            System.out.println(userMenu);
        }
        model.addAttribute("userMenus",userMenus);
        return "starter";
    }

    //菜单管理、角色管理返回UI页面
   /* @RequestMapping("menu/menu_list")
    public String doMenuUI() {
        return "sys/menu_list";
    }*/

    @RequestMapping("{module}/{moduleUI}")
    public String doModuleUI(@PathVariable String moduleUI) {
        return "sys/"+moduleUI;
    }

    //日志管理
 /*   @RequestMapping("log/log_list")
    public String doLogUI() {
        return "sys/log_list";
    }*/

    @RequestMapping("doPageUI")
    public String doPageUI() {
        return "common/page";
    }

    @RequestMapping("doLoginUI")
    public String doLoginUI(){
        return "login";
    }
}
